import java.util.ArrayList;
import java.util.List;

public class Partition {

    public static void main(String[] args) {
        System.out.println("a".equals(new StringBuffer("a").reverse().toString()));
    }

    List<List<String>> ans = new ArrayList<>();
    List<String> list = new ArrayList<>();

    public List<List<String>> partition(String s) {
        process(0, s);
        return ans;
    }

    public void process(int i, String s) {
        if (i == s.length()) {
            ans.add(new ArrayList<>(list));
            return;
        }

        for (int j = i; j < s.length(); j++) {
            String s1 = s.substring(i , j + 1);
            if (isVaild(s1)) {
                list.add(s1);
                process(j + 1, s);
                list.remove(list.size() - 1);
            }
        }
    }

    public boolean isVaild(String s) {
        if (s.length() == 0) return false;
        if (s.equals(new StringBuffer(s).reverse().toString())) return true;
        return false;
    }
}
